package com.example.gymmanagebackend.controller;

import com.example.gymmanagebackend.pojo.Equipment;
import com.example.gymmanagebackend.service.EquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/equipment")
public class EquipmentController {

    @Autowired
    private EquipmentService equipmentService;

    @PostMapping("/add")
    public String addEquipment(@RequestBody Equipment equipment) {
        int result = equipmentService.addEquipment(equipment);
        return result > 0 ? "添加成功" : "添加失败";
    }

    @GetMapping("/all")
    public List<Equipment> getAllEquipments() {
        return equipmentService.getAllEquipments();
    }

    @DeleteMapping("/delete/{id}")
    public String deleteEquipmentById(@PathVariable int id) {
        int result = equipmentService.deleteEquipmentById(id);
        return result > 0 ? "删除成功" : "删除失败";
    }

    @PostMapping("/update/quantity")
    public String updateEquipmentQuantity(@RequestBody Equipment equipment) {
        int result = equipmentService.updateEquipment(equipment);
        return result > 0 ? "更新成功" : "更新失败";
    }

    @GetMapping("/findByName")
    public List<Equipment> findEquipmentByName(@RequestParam String name) {
        return equipmentService.findEquipmentByName(name);
    }
}